package news.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import news.dao.AdminDao;
import news.dao.BaseDao;
import news.entity.Admin;

public class AdminDaoImpl implements AdminDao {
	private Connection connection;
	private PreparedStatement pstmt;
	private ResultSet rs;
	
	@Override
	public int findAdminByLogin(Admin admin) {
		int num = 0;
		try{
			connection = BaseDao.getConnection();
			String sql = "select u_id,u_name,u_pwd from admin where u_name = ? and u_pwd = ?";
			pstmt = connection.prepareStatement(sql);
			pstmt.setString(1, admin.getuName());
			pstmt.setString(2, admin.getuPwd());
			
			rs = pstmt.executeQuery();
			if(rs.next()){
				num = rs.getInt("u_id");
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(rs, pstmt, connection);
		}
		return num;
	}

}
